package com.xuecheng.teaching.agent.hystrix;

import com.xuecheng.api.media.model.dto.MediaDTO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.common.hystrix.BaseAPIHystrix;
import com.xuecheng.common.hystrix.BaseFallbackFactory;
import com.xuecheng.teaching.agent.MediaApiAgent;
import org.springframework.stereotype.Component;

/**
 * Created on 2021/04/05/19:53 周一
 *
 * @author Lantin
 */

@Component
public class MediaApiAgentFallbackFactory extends BaseFallbackFactory<
        BaseAPIHystrix<MediaDTO>,
        MediaApiAgentFallbackFactory.MediaApiAgentHystrix,
        MediaApiAgentFallbackFactory.DevMediaApiAgentHystrix> {

    /**
     * <p>
     * 生产环境降级方法类
     * </p>
     * 返回
     */
   public static class MediaApiAgentHystrix extends BaseAPIHystrix<MediaDTO> implements MediaApiAgent {


        public MediaApiAgentHystrix(Throwable throwable) {
            super(throwable);
        }

        @Override
        public RestResponse<MediaDTO> getMediaById(Long mediaId) {
            return baseFailResult();
        }
    }

    /**
     * <p>
     * 开发环境降级方法类
     * </p>
     * 返回一个默认值
     */
    public static class DevMediaApiAgentHystrix extends BaseAPIHystrix<MediaDTO> implements MediaApiAgent {

        public DevMediaApiAgentHystrix(Throwable throwable) {
            super(throwable);
        }
        @Override
        public RestResponse<MediaDTO> getMediaById(Long mediaId) {
           return RestResponse.success(new MediaDTO());
        }
    }
}
